#include "bvhStack.h"
#include <trax.hpp>

namespace AtomTrace{
    bvhStack::bvhStack()
    {
        current = -1;
        for(int i=0; i<BVH_STACK_SIZE; i++)
        {
            mData[i] = -1;
        }
    }

    bool bvhStack::IsEmpty() const
    {
        return (this->current <= -1);
    }

    bool bvhStack::IsFull() const
    {
        return (this->current >= BVH_STACK_SIZE);
    }

    bool bvhStack::Push(int nodeID)
    {
        if(this->current >= BVH_STACK_SIZE-1) return false;
        current++;
        mData[current] = nodeID;
        return true;
    }

    int bvhStack::Pop()
    {
        if(this->current <= -1) return -1; // empty
        int res = mData[current];
        mData[current] = -1;
        current--;
        return res;
    }

    const int & bvhStack::operator[](int index) const
    {
        if(index >= BVH_STACK_SIZE || index < 0){
            printf("Error, %i exceed stack range[0, %i]\n", index, BVH_STACK_SIZE);
        }
        return mData[index];
    }

    const int & bvhStack::GetCurrent() const
    {
        return current;
    }

    const int bvhStack::GetStackSize() const
    {
        return BVH_STACK_SIZE;
    }

}
